import request from '@/axios'

export function uploadImg(data) {
  return request.post({
    url: '/api/upload/file',
    data,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}
export const bannerApi = {
  page: (params) => {
    return request.get({ url: '/api/banner', params })
  },
  save: (data) => {
    if (data.id) {
      return request.put({ url: '/api/banner/' + data.id, data })
    } else {
      return request.post({ url: '/api/banner', data })
    }
  },
  del: (id) => {
    return request.delete({ url: '/api/banner/' + id })
  }
}
export const activeApi = {
  page: (params) => {
    return request.get({ url: '/api/active', params })
  },
  save: (data) => {
    if (data.id) {
      return request.put({ url: '/api/active/' + data.id, data })
    } else {
      return request.post({ url: '/api/active', data })
    }
  },
  del: (id) => {
    return request.delete({ url: '/api/active/' + id })
  }
}

export const categoryApi = {
  list: (params) => {
    return request.get({ url: '/api/category/list', params })
  },
  page: (params) => {
    return request.get({ url: '/api/category', params })
  },
  save: (data) => {
    if (data.id) {
      return request.put({ url: '/api/category/' + data.id, data })
    } else {
      return request.post({ url: '/api/category', data })
    }
  },
  del: (id) => {
    return request.delete({ url: '/api/category/' + id })
  }
}

export const goodsApi = {
  page: (params) => {
    return request.get({ url: '/api/goods', params })
  },
  save: (data) => {
    if (data.id) {
      return request.put({ url: '/api/goods/' + data.id, data })
    } else {
      return request.post({ url: '/api/goods', data })
    }
  },
  del: (id) => {
    return request.delete({ url: '/api/goods/' + id })
  }
}
export const giftApi = {
  page: (params) => {
    return request.get({ url: '/api/gift', params })
  },
  save: (data) => {
    if (data.id) {
      return request.put({ url: '/api/gift/' + data.id, data })
    } else {
      return request.post({ url: '/api/gift', data })
    }
  },
  del: (id) => {
    return request.delete({ url: '/api/gift/' + id })
  }
}

export const memberApi = {
  page: (params) => {
    return request.get({ url: '/api/member', params })
  },
  save: (data) => {
    if (data.id) {
      return request.put({ url: '/api/member/' + data.id, data })
    } else {
      return request.post({ url: '/api/member', data })
    }
  },
  del: (id) => {
    return request.delete({ url: '/api/member/' + id })
  }
}

export const orderGoodsApi = {
  page: (params) => {
    return request.get({ url: '/api/orderGoods', params })
  },
  save: (data) => {
    if (data.id) {
      return request.put({ url: '/api/orderGoods/' + data.id, data })
    } else {
      return request.post({ url: '/api/orderGoods', data })
    }
  },
  del: (id) => {
    return request.delete({ url: '/api/orderGoods/' + id })
  }
}
export const orderGoodsDetailApi = {
  page: (params) => {
    return request.get({ url: '/api/orderGoodsDetail', params })
  },
  save: (data) => {
    if (data.id) {
      return request.put({ url: '/api/orderGoodsDetail/' + data.id, data })
    } else {
      return request.post({ url: '/api/orderGoodsDetail', data })
    }
  },
  del: (id) => {
    return request.delete({ url: '/api/orderGoodsDetail/' + id })
  }
}
export const orderGiftApi = {
  page: (params) => {
    return request.get({ url: '/api/orderGift', params })
  },
  save: (data) => {
    if (data.id) {
      return request.put({ url: '/api/orderGift/' + data.id, data })
    } else {
      return request.post({ url: '/api/orderGift', data })
    }
  },
  del: (id) => {
    return request.delete({ url: '/api/orderGift/' + id })
  }
}
